<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<c:set var="webroot" value="${pageContext.request.contextPath}" />
<html>
<head>
	<meta charset="utf-8">
	<title>权限设置</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="format-detection" content="telephone=no">
	<link rel="stylesheet" href="${webroot}/static/layui/css/layui.css" media="all" />
	<link rel="stylesheet" href="${webroot}/static/css/public.css" media="all" />
</head>
<body class="childrenBody">
<form class="layui-form" style="width:80%;">
    <input type="hidden" id="roleId" value="${role.roleId}">
    <input type="hidden" id="roleName" value="${role.roleName}">
    <div class="layui-table-body layui-table-main" style="overflow: hidden;">
       <table cellspacing="0" cellpadding="0" border="0" class="layui-table">
          <tbody>
          <div class="layui-form-item layui-row layui-col-xs12">
	                                当前角色:${role.roleName}
          </div>
          <c:forEach items="${list}" var="l">
            <tr data-index="0" class="">
              <td data-field="id" data-key="1-0-0" class="">
                 <input type="checkbox" id="${l.isShow}" name="ownerCost" lay-skin="primary" class="ownerCost" lay-filter="owner_one" title="${l.title}" value="${l.resourceId}"> 
              </td>
            </tr>
            <tr data-index="0" class="">
                 <c:forEach items="${l.list}" var="s">
                   <td data-field="id" data-key="1-0-0" class="">
                        <input type="checkbox" id="${s.isShow}" name="ownerCost" lay-skin="primary" class="ownerCost" lay-filter="owner_one" title="${s.title}" value="${s.resourceId}">            
                   </td>
                 </c:forEach>
            </tr>
          </c:forEach>
         <!--    <tr data-index="0" class="">
              <td data-field="id" data-key="1-0-0" class="">
                 <div class="layui-unselect layui-form-checkbox" lay-skin="primary"><span>内容系统</span><i class="layui-icon layui-icon-ok"></i></div>
                 <div class="layui-unselect layui-form-checkbox" lay-skin="primary"><span>内容系统1</span><i class="layui-icon layui-icon-ok"></i></div>
              </td>
            </tr> -->
          </tbody>
       </table>
    </div>
    <div class="layui-form-item layui-row layui-col-xs12" style="border: 1px solid #9e9e9e47;">
		<div class="layui-input-block" style=" text-align: center;" >
		    <input type="checkbox" lay-skin="primary" id="owner_all"  lay-filter="owner_all" title="选择全部" value="">
		</div>
	</div>
	<div class="layui-form-item layui-row layui-col-xs12">
		<div class="layui-input-block" style=" text-align: center;">
			<button class="layui-btn" lay-submit="" lay-filter="addRole" style="width: 90px;">提交</button>
		<%-- 	<c:if test="${show != null}">
	    	   <button type="reset" class="layui-btn layui-btn-primary" onclick="close_self();">取消</button>
	        </c:if> --%>
	         <button type="reset" class="layui-btn layui-btn-primary" onclick="close_self();">取消</button>
		</div>
	</div>
</form>
<script type="text/javascript" src="${webroot}/static/layui/layui.js"></script>
<script src="${webroot}/static/js/jquery.min.js" charset="utf-8"></script>
<script>
layui.use(['form','layer'],function(){
    var form = layui.form
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery;
	$("input:checkbox[name='ownerCost']").each(function(i){
    	var id = $(this).attr("id");
    	if(id != ''){
    	   $(this).prop("checked",true);
    	   form.render('checkbox');
    	}
    });
    form.on("submit(addRole)",function(data){
        var id = new Array(); var name = new Array();
    	$("input:checkbox[name='ownerCost']:checked").each(function(i){
    	        id[i] = $(this).val();
    	        name[i] = $(this).attr("title");
    	});
        var index = top.layer.msg('数据提交中，请稍候',{icon: 16,time:false,shade:0.8});
        // 实际使用时的提交信息
        $.post("/admin/role/update",{
        	roleId : $("#roleId").val(),  
        	resourceId: id.join(","),  
        	resourceName: name.join(","),
        	roleName : $("#roleName").val(),
        	record : "设置权限:"
         },function(res){
        	 var data=JSON.parse(res);
        	 if(data.success){
        		top.layer.close(index);
  	            top.layer.msg("操作成功,相关用户退出后重新登录生效!"); 
        	 }else{
        		 top.layer.msg(data.message);
        	 }
        })
        return false;
    })
    
    form.on('checkbox(owner_all)', function(data){
    	var a =data.elem.checked;
    	if(a == true){
    		 $(".ownerCost").prop("checked",true);
             form.render('checkbox');
    	}else{
    		 $(".ownerCost").prop("checked",false);
             form.render('checkbox');
    	}
    });

    //格式化时间
    function filterTime(val){
        if(val < 10){
            return "0" + val;
        }else{
            return val;
        }
    }
    //定时发布
    var time = new Date();
    var submitTime = time.getFullYear()+'-'+filterTime(time.getMonth()+1)+'-'+filterTime(time.getDate())+' '+filterTime(time.getHours())+':'+filterTime(time.getMinutes())+':'+filterTime(time.getSeconds());

})
function close_self() {
	window.location.href="/admin/role/showlist";
}
</script>
</body>
</html>